<?php
// app/Http/Requests/ProgrammingLanguageRequest.php
namespace App\Http\Requests;

use App\Models\TrainingLevelHead;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;


class TrainingLevelContentRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case "POST":
                return [
                    'training_level_head_id' => ['required','integer', Rule::exists(TrainingLevelHead::getTableName(),'id')],
                    'question' => ['required'],
                    'code_example' => ['required'],
                ];
            case "PUT":
            case "PATCH":
                $traininglevelcontent = $this->route('traininglevelcontent');
                return [
                    'training_level_head_id' => ['nullable','integer', Rule::exists(TrainingLevelHead::getTableName(),'id')],
                    'question' => ['nullable'],
                    'code_example' => ['nullable']
                ];
        }
        return [];
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 获取验证错误的自定义属性
     *
     * @return array
     */
    public function attributes()
    {
        // 替换 :attribute 占位符内容
        return [
            'training_level_head_id' => '管卡标题id',
            'question' => '问题',
            'code_example' => '参考答案'
        ];
    }
}
